from typing import Optional
from datetime import datetime, date
from sqlmodel import SQLModel, Field
from .resBase import BaseResponse, PaginationRequest, PaginatedResponse, PaginationInfo


# 欧洲18万数据表模型
class MatchPredictEurope18wan(SQLModel, table=True):
    __tablename__: str = "v_match_europe_18wan"
    
    event_name: Optional[str] = Field(default=None, max_length=100, description="赛事名称")
    fid: Optional[int] = Field(default=None, primary_key=True, description="比赛ID")
    season_id: Optional[int] = Field(default=None, description="赛季ID")
    homeid: Optional[int] = Field(default=None, description="主队ID")
    awayid: Optional[int] = Field(default=None, description="客队ID")
    status: Optional[str] = Field(default=None, max_length=10, description="比赛状态")
    order_num: Optional[str] = Field(default=None, max_length=20, description="比赛编号")
    ownerdate: Optional[date] = Field(default=None, description="所属日期")
    matchtime: Optional[datetime] = Field(default=None, description="比赛时间")
    homesxname: Optional[str] = Field(default=None, max_length=100, description="主队名称")
    awaysxname: Optional[str] = Field(default=None, max_length=100, description="客队名称")
    homescore: Optional[int] = Field(default=None, description="主队得分")
    awayscore: Optional[int] = Field(default=None, description="客队得分")
    home_initial: Optional[float] = Field(default=None, description="主队初始赔率")
    draw_initial: Optional[float] = Field(default=None, description="平局初始赔率")
    away_initial: Optional[float] = Field(default=None, description="客队初始赔率")
    is_setting_range: Optional[int] = Field(default=None, description="是否设置范围")


# 欧洲18万数据查询条件模型
class MatchPredictEurope18wanCondition(PaginationRequest):
    event_name: Optional[str] = Field(default=None, description="赛事名称")
    season_id: Optional[int] = Field(default=None, description="赛季ID")
    homeid: Optional[int] = Field(default=None, description="主队ID")
    awayid: Optional[int] = Field(default=None, description="客队ID")
    status: Optional[str] = Field(default=None, description="比赛状态")
    order_num: Optional[str] = Field(default=None, description="订单号")
    homesxname: Optional[str] = Field(default=None, description="主队名称")
    awaysxname: Optional[str] = Field(default=None, description="客队名称")
    
    # 日期范围字段
    ownerdate_s: Optional[str] = Field(default=None, description="所属日期开始 yyyy-mm-dd")
    ownerdate_e: Optional[str] = Field(default=None, description="所属日期结束 yyyy-mm-dd")
    matchtime_s: Optional[str] = Field(default=None, description="比赛时间开始 yyyy-mm-dd")
    matchtime_e: Optional[str] = Field(default=None, description="比赛时间结束 yyyy-mm-dd")
    
    # 比分范围字段
    homescore_min: Optional[int] = Field(default=None, description="主队得分最小值")
    homescore_max: Optional[int] = Field(default=None, description="主队得分最大值")
    awayscore_min: Optional[int] = Field(default=None, description="客队得分最小值")
    awayscore_max: Optional[int] = Field(default=None, description="客队得分最大值")
    
    # 初始赔率范围字段
    home_initial_min: Optional[float] = Field(default=None, description="主队初始赔率最小值")
    home_initial_max: Optional[float] = Field(default=None, description="主队初始赔率最大值")
    draw_initial_min: Optional[float] = Field(default=None, description="平局初始赔率最小值")
    draw_initial_max: Optional[float] = Field(default=None, description="平局初始赔率最大值")
    away_initial_min: Optional[float] = Field(default=None, description="客队初始赔率最小值")
    away_initial_max: Optional[float] = Field(default=None, description="客队初始赔率最大值")
    
    is_setting_range: Optional[int] = Field(default=None, description="是否设置范围")


# 欧洲18万数据最小最大值表模型
class MatchesEurope18wMinMax(SQLModel, table=True):
    __tablename__: str = "matches_europe_18w_min_max"
    
    fid: int = Field(primary_key=True, description="比赛ID")
    home_odds_min: Optional[float] = Field(default=None, description="主队赔率最小值")
    home_odds_max: Optional[float] = Field(default=None, description="主队赔率最大值")
    draw_odds_min: Optional[float] = Field(default=None, description="平局赔率最小值")
    draw_odds_max: Optional[float] = Field(default=None, description="平局赔率最大值")
    away_odds_min: Optional[float] = Field(default=None, description="客队赔率最小值")
    away_odds_max: Optional[float] = Field(default=None, description="客队赔率最大值")


# 欧洲18万数据最小最大值更新请求模型
class MatchesEurope18wMinMaxUpdateRequest(SQLModel):
    fid: int = Field(description="比赛ID")
    home_odds_min: Optional[float] = Field(default=None, description="主队赔率最小值")
    home_odds_max: Optional[float] = Field(default=None, description="主队赔率最大值")
    draw_odds_min: Optional[float] = Field(default=None, description="平局赔率最小值")
    draw_odds_max: Optional[float] = Field(default=None, description="平局赔率最大值")
    away_odds_min: Optional[float] = Field(default=None, description="客队赔率最小值")
    away_odds_max: Optional[float] = Field(default=None, description="客队赔率最大值")


# 欧洲18万数据最小最大值响应模型
class MatchesEurope18wMinMaxResponse(BaseResponse):
    data: Optional[MatchesEurope18wMinMax] = None


# 欧洲18万数据响应模型
class MatchPredictEurope18wanResultResponse(PaginatedResponse):
    data: Optional[list[MatchPredictEurope18wan]] = None


# t_293_18w表模型
class MatchPredictEurope29318wan(SQLModel, table=True):
    __tablename__: str = "t_293_18w"
    
    id: int = Field(primary_key=True,description="ID")
    matchtime: Optional[str] = Field(default=None, max_length=50, description="比赛时间")
    event_name: Optional[str] = Field(default=None, max_length=50, description="赛事名称")
    homesxname: Optional[str] = Field(default=None, max_length=50, description="主队名称")
    homescore: Optional[int] = Field(default=None, description="主队得分")
    awayscore: Optional[int] = Field(default=None, description="客队得分")
    awaysxname: Optional[str] = Field(default=None, max_length=50, description="客队名称")
    home_initial: Optional[float] = Field(default=None, description="主队初始赔率")
    draw_initial: Optional[float] = Field(default=None, description="平局初始赔率")
    away_initial: Optional[float] = Field(default=None, description="客队初始赔率")
    home_final: Optional[float] = Field(default=None, description="主队最终赔率")
    draw_final: Optional[float] = Field(default=None, description="平局最终赔率")
    away_final: Optional[float] = Field(default=None, description="客队最终赔率")


# t_293_18w表查询条件模型
class MatchPredictEurope29318wanCondition(PaginationRequest):
    event_name: Optional[str] = Field(default=None, description="赛事名称")
    homesxname: Optional[str] = Field(default=None, description="主队名称")
    awaysxname: Optional[str] = Field(default=None, description="客队名称")
    
    # 比分范围字段
    homescore_min: Optional[int] = Field(default=None, description="主队得分最小值")
    homescore_max: Optional[int] = Field(default=None, description="主队得分最大值")
    awayscore_min: Optional[int] = Field(default=None, description="客队得分最小值")
    awayscore_max: Optional[int] = Field(default=None, description="客队得分最大值")
    
    # 初始赔率范围字段
    home_initial_min: Optional[float] = Field(default=None, description="主队初始赔率最小值")
    home_initial_max: Optional[float] = Field(default=None, description="主队初始赔率最大值")
    draw_initial_min: Optional[float] = Field(default=None, description="平局初始赔率最小值")
    draw_initial_max: Optional[float] = Field(default=None, description="平局初始赔率最大值")
    away_initial_min: Optional[float] = Field(default=None, description="客队初始赔率最小值")
    away_initial_max: Optional[float] = Field(default=None, description="客队初始赔率最大值")
    
    # 最终赔率范围字段
    home_final_min: Optional[float] = Field(default=None, description="主队最终赔率最小值")
    home_final_max: Optional[float] = Field(default=None, description="主队最终赔率最大值")
    draw_final_min: Optional[float] = Field(default=None, description="平局最终赔率最小值")
    draw_final_max: Optional[float] = Field(default=None, description="平局最终赔率最大值")
    away_final_min: Optional[float] = Field(default=None, description="客队最终赔率最小值")
    away_final_max: Optional[float] = Field(default=None, description="客队最终赔率最大值")


# t_293_18w表响应模型
class MatchPredictEurope29318wanResultResponse(PaginatedResponse):
    data: Optional[list[MatchPredictEurope29318wan]] = None


# v_293_init_same_europe_final表模型
class V293InitSameEuropeFinal(SQLModel, table=True):
    __tablename__: str = "v_293_init_same_europe_final"
    
    
    fid: int= Field(primary_key=True, description="比赛ID")
    event_name: Optional[str] = Field(default=None, max_length=100, description="赛事名称")
    homesxname: Optional[str] = Field(default=None, max_length=100, description="主队名称")
    awaysxname: Optional[str] = Field(default=None, max_length=100, description="主队名称")
    matchtime: Optional[datetime] = Field(default=None, max_length=100, description="比赛时间")
    homescore: Optional[int] = Field(default=None, description="主得分")    
    awayscore: Optional[int] = Field(default=None, description="客得分")        
    home_initial: Optional[float] = Field(default=None, description="主队初始赔率")
    theory_home_initial: Optional[float] = Field(default=None, description="理论主队初始赔率")
    home_diff: Optional[float] = Field(default=None, description="主队赔率差值")
    draw_initial: Optional[float] = Field(default=None, description="平局初始赔率")
    theory_draw_initial: Optional[float] = Field(default=None, description="理论平局初始赔率")
    draw_diff: Optional[float] = Field(default=None, description="平局赔率差值")
    away_initial: Optional[float] = Field(default=None, description="客队初始赔率")
    theory_away_initial: Optional[float] = Field(default=None, description="理论客队初始赔率")
    away_diff: Optional[float] = Field(default=None, description="客队赔率差值")
    return_rate: Optional[float] = Field(default=None, description="回报率")
    total_matches: Optional[int] = Field(default=None, description="总比赛数")
    home_win_count: Optional[int] = Field(default=None, description="主队获胜场次")
    draw_count: Optional[int] = Field(default=None, description="平局场次")
    away_win_count: Optional[int] = Field(default=None, description="客队获胜场次")
    home_win_rate: Optional[float] = Field(default=None, description="主队胜率")
    draw_rate: Optional[float] = Field(default=None, description="平局率")
    away_win_rate: Optional[float] = Field(default=None, description="客队胜率")
    status: Optional[str] = Field(default=None, max_length=10, description="比赛状态")
    


# v_293_init_same_europe_final表查询条件模型
class V293InitSameEuropeFinalCondition(PaginationRequest):
    event_name: Optional[str] = Field(default=None, description="赛事名称")
    fid: Optional[int] = Field(default=None, description="比赛ID")
    status: Optional[str] = Field(default=None, description="赛事状态")
    home_initial_min:Optional[float] = Field(default=None, description="主队赔率最小")
    home_initial_max:Optional[float] = Field(default=None, description="主队赔率最大")
    draw_initial_min:Optional[float] = Field(default=None, description="平赔率最小")
    draw_initial_max:Optional[float] = Field(default=None, description="平赔率最大")
    away_initial_min:Optional[float] = Field(default=None, description="客队赔率最小")
    away_initial_max:Optional[float] = Field(default=None, description="客队赔率最大")
    
    # 范围查询字段
    home_diff_min: Optional[float] = Field(default=None, description="主队赔率差值最小值")
    home_diff_max: Optional[float] = Field(default=None, description="主队赔率差值最大值")
    draw_diff_min: Optional[float] = Field(default=None, description="平局赔率差值最小值")
    draw_diff_max: Optional[float] = Field(default=None, description="平局赔率差值最大值")
    away_diff_min: Optional[float] = Field(default=None, description="客队赔率差值最小值")
    away_diff_max: Optional[float] = Field(default=None, description="客队赔率差值最大值")


# v_293_init_same_europe_final表响应模型
class V293InitSameEuropeFinalResultResponse(PaginatedResponse):
    data: Optional[list[V293InitSameEuropeFinal]] = None


# 欧洲18万返回测试统计数据查询条件模型
class MatchPredictEurope18wReturnTestStatisticsCondition(SQLModel):
    event_name: Optional[str] = Field(default=None, description="赛事名称")
    
    
    # 初始赔率范围字段
    home_initial_min: Optional[float] = Field(default=None, description="主队初始赔率最小值")
    home_initial_max: Optional[float] = Field(default=None, description="主队初始赔率最大值")
    draw_initial_min: Optional[float] = Field(default=None, description="平局初始赔率最小值")
    draw_initial_max: Optional[float] = Field(default=None, description="平局初始赔率最大值")
    away_initial_min: Optional[float] = Field(default=None, description="客队初始赔率最小值")
    away_initial_max: Optional[float] = Field(default=None, description="客队初始赔率最大值")
    
    # 赔率差值范围字段
    home_diff_min: Optional[float] = Field(default=None, description="主队赔率差值最小值")
    home_diff_max: Optional[float] = Field(default=None, description="主队赔率差值最大值")
    draw_diff_min: Optional[float] = Field(default=None, description="平局赔率差值最小值")
    draw_diff_max: Optional[float] = Field(default=None, description="平局赔率差值最大值")
    away_diff_min: Optional[float] = Field(default=None, description="客队赔率差值最小值")
    away_diff_max: Optional[float] = Field(default=None, description="客队赔率差值最大值")


# 欧洲18万返回测试统计数据模型
class MatchPredictEurope18wReturnTestStatistics(SQLModel):
    total_matches: int = Field(description="总比赛场次")
    home_wins: int = Field(description="主胜场次")
    draws: int = Field(description="平局场次")
    away_wins: int = Field(description="客胜场次")
    home_win_rate: float = Field(description="主胜率")
    draw_rate: float = Field(description="平局率")
    away_win_rate: float = Field(description="客胜率")


# 欧洲18万返回测试统计数据响应模型
class MatchPredictEurope18wReturnTestStatisticsResponse(BaseResponse):
    data: Optional[MatchPredictEurope18wReturnTestStatistics] = None
